package com.sdkj.controller.meetingroom;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.sdkj.controller.base.BaseController;
import com.sdkj.entity.Page;
import com.sdkj.service.meetingroom.MeetingRoomService;
import com.sdkj.service.meetingroom.MrReservationService;
import com.sdkj.util.Const;
import com.sdkj.util.DateUtil;
import com.sdkj.util.PageData;


/** 
 * 类名称：MrReservationController
 * 创建人：FH 
 * 创建时间：2017-05-16
 */
@Controller
@RequestMapping(value="/appointment")
public class AppointmentStatusController extends BaseController {
	
	String menuUrl = "reservation/list.do"; //菜单地址(权限用)
	@Resource(name="mrreservationService")
	private MrReservationService mrreservationService;
	
	@Resource(name="meetingroomService")
	private MeetingRoomService meetingroomService;
	
	
	
	
	/**
	 * 列表
	 */
	@RequestMapping(value="/list")
	public ModelAndView list(Page page){
		logBefore(logger, "列表MrReservation");
		ModelAndView mv = this.getModelAndView();
		PageData pd = new PageData();
		try{
			pd = this.getPageData();
			String time=pd.getString("time");
			if (null==time) {
				time=DateUtil.getDay();
				pd.put("time", time);
			}
			List<PageData>	varList = meetingroomService.listAll(pd);	//列出MrReservation列表
			List<PageData> meetlist = mrreservationService.findDateById(pd);
			mv.setViewName("meetingroom/appointment/mrreStatus_list");
			mv.addObject("meetlist", meetlist);
			mv.addObject("varList", varList);
			mv.addObject("pd", pd);
			mv.addObject(Const.SESSION_QX,this.getHC());	//按钮权限
		} catch(Exception e){
			logger.error(e.toString(), e);
		}
		return mv;
	}
	
	
	
	


	
	
	
	/* ===============================权限================================== */
	public Map<String, String> getHC(){
		Subject currentUser = SecurityUtils.getSubject();  //shiro管理的session
		Session session = currentUser.getSession();
		return (Map<String, String>)session.getAttribute(Const.SESSION_QX);
	}
	/* ===============================权限================================== */
	
	@InitBinder
	public void initBinder(WebDataBinder binder){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		binder.registerCustomEditor(Date.class, new CustomDateEditor(format,true));
	}
}
